package com.qust.edu.aliyun.controller;

import com.qust.edu.aliyun.dto.ProductDto;
import com.qust.edu.aliyun.pojo.Product;
import com.qust.edu.aliyun.service.ProductService;
import com.qust.edu.aliyun.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * projectName: aliyun_guanli
 *
 * @author: 孙春娟
 * time: 2021/9/28 14:09
 * description:
 */
@RestController
@CrossOrigin("*")
@RequestMapping("product")
public class ProductController {

    @Autowired
    private ProductService productService;


    /**
     * 查询全部商品
     * @param productDto
     * @return
     */
    @PostMapping("getAllProduct")
    public Object getAllProduct(@RequestBody ProductDto productDto  ){
        Object r= productService.getProductByCategory(productDto);
        return  r;
    }

    /**
     * 关键字查询
     * @param productDto
     * @return
     */
    @PostMapping("getProductBySearch")
    public Object getProductBySearch(@RequestBody ProductDto productDto  ){
        Object r=productService.getProductBySearch(productDto);
        return  r;
    }

    /**
     * 删除商品接口
     * @param productDto
     * @return
     */
    @PostMapping("getDeleteProduct")
    public Object getDeleteProduct(@RequestBody ProductDto productDto){

        R r = productService.getDeleteProduct(productDto);

        return  r;
    }

    /**
     * 添加商品接口
     * @param
     * @return
     */
    @PostMapping("getAddProduct")
    public Object getAddProduct(@RequestBody Product product){
        R r=productService.getAddProduct(product);

        return r;
    }

    /**
     * 修改商品接口
     * @param
     * @return
     */
    @PostMapping("getModifyProduct")
    public Object getModifyProduct(@RequestBody Product product){
        System.out.println("product =------------- " + product);
        R r=productService.getModifyProduct(product);
        return r;
    }

}
